﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Bll;
using System.Data;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;
using AspNetCs.Model;
public partial class AjaxXml_SacrificeAjax : BasePage
{
    protected string Cnt = "";
    protected int id = 0;
    protected string channelStr = "";
    protected int num = 0;

    protected void Page_Load(object sender, EventArgs e)
    {


        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        if (Request["channel"] != null)
        {
            channelStr = Request["channel"].ToString();
        }
        if (Request["num"] != null)
        {
            num = StringHelper.isNumber_int(Request["num"].ToString());
        }
        if (channelStr == "" || id <= 0)
        {
            Response.Write("参数错误！");
            Response.End();
        }


        if (Request["Cnt"] != null)
        {
            Cnt = Request["Cnt"].ToString();
        }
        Channel_Type CType = (Channel_Type)Enum.Parse(typeof(Channel_Type), channelStr);



        GetStringData_lable lb = new GetStringData_lable();

        DataTable dt = new DataTable();
        switch (CType)
        {
            case Channel_Type.cemetery:
                List<Cemetery_AddNumId_Model> lists = Cemetery_AddNumId_Bll.CreateNew.GetData(" Cemeteryid=" + id);
                if (lists.Count > 0)
                {
                    string Selectid = "";
                    for (int i = 0; i < lists.Count; i++)
                    {
                        Selectid += Memorial_Bll.CreateNew.GetModel(" where Numid='" + lists[i].NumId + "'").Id.ToString();

                        if (i != lists.Count - 1)
                        {
                            Selectid += ",";

                        }
                    }
                    dt = SacrificeList_Bll.CreateNew.GetDataTable(" TypeId in(" + Selectid + ") and channelId='" + Channel_Type.memorial + "'  order by id desc ");

                }

                break;
            default:
                dt = SacrificeList_Bll.CreateNew.GetDataTable(" TypeId=" + id + " and channelId='" + channelStr + "'  order by id desc ");
                break;
        }


        if (dt.Rows.Count > 0)
        {
            string str = "";
            int i = 0;
            DataTable dt2 = new DataTable();
            dt2 = dt.Clone();
            foreach (DataRow dr in dt.Rows)
            {

                DataRow dr2 = dt2.NewRow();//如果在此直接用dt2.Rows.Add(Drr)会报错，因为Drr的引用现在为 dt1所用
                dr2.ItemArray = dr.ItemArray;
                dt2.Rows.Add(dr2);
                str += lb.GetResultStr(Cnt, dt2);
                i++;
                dt2.Clear();

                if (i >= num) { break; }
            }


            Response.Write(str);
        }
        else
        {
            Response.Write("<center>暂无最新纪念</center>");
        }


    }
}
